home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 June / Cd Pc Users 9.iso / prog / inst / baslibs / clsmappi.cls < prev    next >
Encoding:
Text File  |  1996-12-04  |  2.2 KB  |  106 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsMapping"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. '
  11. '  This is very similar to a Collection object.
  12. '  However, it is more resiliant, requires a
  13. '  key, and a specific order is not kept.
  14. '
  15. '  It is actually very similar to a
  16. '  mapping in lpc (mud)
  17. '
  18. '  .Item() sets a new key, changes an old
  19. '  key, and returns a requested value by
  20. '  key (or Null if none is found)
  21. '  Keys can also be retrieved (by number)
  22. '
  23. Private vData As New Collection
  24. Private vKeys As New Collection
  25.  
  26.  
  27.  
  28. Public Property Get Count() As Long
  29.    Count = vData.Count
  30. End Property
  31. Public Function GetItem(Key As Variant, Default As Variant) As Variant
  32.    On Error GoTo ErrorHandle
  33.    
  34.    If VarType(vData(Key)) = vbObject Then
  35.       Set GetItem = vData(Key)
  36.    Else
  37.       GetItem = vData(Key)
  38.    End If
  39.    
  40.    Exit Function
  41.    
  42.    
  43. ErrorHandle:
  44.    If VarType(Default) = vbObject Then
  45.       Set GetItem = Default
  46.    Else
  47.       GetItem = Default
  48.    End If
  49. End Function
  50.  
  51. Public Property Get Item(Key As Variant) As Variant
  52.    On Error GoTo GetError
  53.    
  54.    If VarType(vData(Key)) = vbObject Then
  55.      Set Item = vData(Key)
  56.    Else
  57.       Item = vData(Key)
  58.    End If
  59.    
  60.    Exit Property
  61.    
  62. GetError:
  63.    Item = Null
  64. End Property
  65. Public Property Set Item(Key As Variant, v As Variant)
  66.    On Error Resume Next
  67.    vData.Remove Key
  68.    If Err > 0 Then vKeys.Add Key, Key
  69.    vData.Add v, Key
  70. End Property
  71.  
  72. Public Property Let Item(Key As Variant, v As Variant)
  73.    On Error Resume Next
  74.    vData.Remove Key
  75.    If Err > 0 Then vKeys.Add Key, Key
  76.    vData.Add v, Key
  77. End Property
  78.  
  79.  
  80. Public Function Key(ByVal i As Long) As Variant
  81.    On Error Resume Next
  82.    Key = vKeys(i)
  83.    If Err > 0 Then Key = Null
  84. End Function
  85.  
  86. Public Function Remove(Key As Variant) As Boolean
  87.    On Error GoTo ErrorHandle
  88.    
  89.    vData.Remove Key
  90.    vKeys.Remove Key
  91.    Remove = True
  92.    Exit Function
  93.  
  94. ErrorHandle:
  95.    Remove = False
  96. End Function
  97.  
  98. '
  99. ' Clears the mapping
  100. '
  101. Public Sub Clear()
  102.    Set vData = New Collection
  103.    Set vKeys = New Collection
  104. End Sub
  105.  
  106.